package com.open.dome.until;

import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;

public class HttpUntil {


    public static String doPostJson(String apiUrl, String jsonParams) {
        StringBuffer sbResult = new StringBuffer();

        try {
            URL url = new URL(apiUrl);
            HttpURLConnection conn = (HttpURLConnection)url.openConnection();
            conn.setDoOutput(true);
            conn.setDoInput(true);
            conn.setUseCaches(false);
            conn.setRequestMethod("POST");
            conn.setRequestProperty("Connection", "Keep-Alive");
            conn.setRequestProperty("Charset", "UTF-8");
            byte[] data = jsonParams.getBytes("UTF-8");
            conn.setRequestProperty("Content-Length", String.valueOf(data.length));
            conn.setRequestProperty("Content-Type", "application/json");
            conn.connect();
            OutputStream out = new DataOutputStream(conn.getOutputStream());
            out.write(data);
            out.flush();
            out.close();
            if (200 == conn.getResponseCode()) {
                InputStream inputStream = conn.getInputStream();

                try {
                    String readLine = null;
                    BufferedReader responseReader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));

                    while((readLine = responseReader.readLine()) != null) {
                        sbResult.append(readLine).append("\n");
                    }

                    responseReader.close();
                } catch (Exception var12) {
                    var12.printStackTrace();
                }
            }
        } catch (Exception var13) {
            var13.printStackTrace();
        }

        return sbResult.toString();
    }
}
